#include "timer.h"



Timer::Timer()
{
 
}
 
Timer::~Timer()
{
 
}
 
void Timer::Start()
{
    LONGLONG    perf_cnt = 0;
 
    if (QueryPerformanceFrequency((LARGE_INTEGER *) &perf_cnt))
    {
        time_scale = 1.0f / perf_cnt;
        QueryPerformanceCounter((LARGE_INTEGER *) &start_time);
        last_time = start_time;
        this->UpdateFunc = &Timer::GetTimePerf;
    }
    else
    {
        start_time = last_time = timeGetTime();
        time_scale = 0.001f;
        this->UpdateFunc = &Timer::GetTime;
    }
}
 
float Timer::GetTime()
{
    return (float)timeGetTime();
}
 
float Timer::GetTimePerf()
{
    QueryPerformanceCounter((LARGE_INTEGER *) &cur_time);
    
    return (float)cur_time;
}
 
float Timer::GetTotalElapsedTime()
{
    cur_time = (LONGLONG)(this->*UpdateFunc)();
 
    time_elapsed = (cur_time - start_time) * time_scale;
    last_time = cur_time;
 
    return time_elapsed;
}
 
float Timer::GetElapsedTime()
{
    cur_time = (LONGLONG)(this->*UpdateFunc)();
 
    time_elapsed = (cur_time - last_time) * time_scale;
    last_time = cur_time;
 
    return time_elapsed;
}